//************************************************************************
/// <copyrigth>2024-2025 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Cross-Platform named pipe which is for process' communication
/// It just can flow to a way,such as A->B, Server for read data,Client for write data
///</describe>
/// <date>2024/4/1</date>
///***********************************************************************
#ifndef NAMEDPIPE_H
#define NAMEDPIPE_H

#include <string>
#include "ModuleLoader/ModuleConfig.h"

namespace SystemTool
{
    class CLASS_ITEM NamedPipe
    {
    public:
        // Construct the obj
        NamedPipe();

        // Destruct the obj
        ~NamedPipe();

    private:
        // Copy construct
        NamedPipe(const NamedPipe &other) = delete;

        // Assignment
        NamedPipe& operator=(const NamedPipe &other) = delete;

    public:
        // Create pipe
        bool Create(bool bIsServer, std::string strName = "MyPipe");

        // Read data
        int ReadBytes(char *pData, int iDataSize);

        // Write data
        int WriteBytes(const char *pData, int iDataSize);

        // Destroy pipe
        bool Destroy();

    private:
    #ifdef _WIN32
        // Handle
        void* m_hPipe;
    #else
        // File fd
        int m_hPipe;
    #endif
    };
}

#endif // NAMEDPIPE_H
